package cn.sendto.mapper;


import java.sql.ResultSet;
import java.sql.SQLException;

import cn.sendto.model.StudentEntity;

public class StudentMapper implements IRowMapper<StudentEntity> {

	@Override
	public StudentEntity rowMapper(ResultSet rs) throws SQLException {

		StudentEntity entity = new StudentEntity();

		try {
			entity.setStudentId(rs.getString("studentid"));
			entity.setStudentName(rs.getString("studentname"));
			entity.setGender(rs.getString("gender"));
			entity.setAge(rs.getInt("age"));
			entity.setAddress(rs.getString("address"));
			entity.setStudentno(rs.getString("studentno"));
			entity.setTel(rs.getString("telphone"));
			entity.setClassId(rs.getInt("classid"));
			entity.setPassword(rs.getString("password"));
			if(isExistColumn(rs, "classname"))
			    entity.setClassName(rs.getString("classname"));
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("数据映射异常"+e.toString());
		}

		return entity;
	}
	 public boolean isExistColumn(ResultSet rs, String columnName) {
		    try {
		        if (rs.findColumn(columnName) > 0 ) {
		            return true;
		        } 
		    }
		    catch (SQLException e) {
		        return false;
		    }
		     
		    return false;
		}

}
